home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / tp6sb110.zip / SBVOICE.PAS < prev   
Pascal/Delphi Source File  |  1991-03-27  |  10KB  |  335 lines

  1. {---------------------------------------------------------------------------
  2.                    Unit SBVoice (v1.10) for Turbo Pascal 6.0
  3.        For interfacing with the SoundBlaster's digitized voice channel.
  4.            Copyright (c) 1991, Amit K. Mathur, Windsor, Ontario.
  5.  
  6.                         By: Amit K. Mathur
  7.                             3215 St. Patrick's Drive
  8.                             Windsor, Ontario
  9.                             N9E 3H2 CANADA
  10.                         Ph: (519) 966-6924
  11.  
  12.  Networks:  RIME(tm) R/O ->WINDSOR, ILink (Shareware), NA-Net (Gaming),
  13.             WWIVNet (#198@5950), or direct on NorthSTAR (519)735-1504.
  14.  
  15.  These routines are released to the public domain.  However I will gladly
  16.  accept contributions towards further development of this and other products.
  17.  Please send any changes or improvements my way.  And I'm interested in
  18.  other SoundBlaster utilities and programming tools.  Thanks in advance.
  19.  --------------------------------------------------------------------------}
  20.  
  21. {$O+,F+}
  22. { Allow this Unit to Be Overlayed (doesn't affect compilation if you decide
  23.   not to overlay it), and force far calls.                                 }
  24.  
  25. unit SBVoice;
  26.  
  27. interface
  28.  
  29. uses MemAlloc;                                    { Memory Allocation Proc }
  30.  
  31. var
  32. {$IFNDEF NoSBVoiceArray}                          { to use your own        }
  33.      SoundFile: Array[1..25000] of byte;          { whatever size you want }
  34. {$ENDIF}
  35.      sgSBDriver, ofSBDriver: word;                { seg and ofs of Driver  }
  36.      SBDriver: Pointer;                           { pointer to the driver  }
  37.      StatusWord: Word;                            { stores SB status       }
  38.      SBFound: Boolean;                            { whether Init worked    }
  39.  
  40. procedure loaddriver(fi:string);
  41. { Loads CT-VOICE.DRV into memory.  'fi' is the path to the driver.         }
  42.  
  43. procedure closedriver;
  44. { Clean up routine.  Not really necessary if your program is over.         }
  45.  
  46. procedure loadvoice(f:string;start,size:word);
  47. { Load 'f' into memory.  Start is the start of the area within
  48.   'f' to load and size is the amount to laod.  If you set size to 0
  49.   then it will load the entire file.                                      }
  50.  
  51. function sb_getversion:integer;
  52. { Get the version number of the CT-VOICE.DRV
  53.   Returns the Version number                                              }
  54.  
  55. function sb_init:integer;
  56. { Initialize the SoundBlaster.  Call this right after load driver, unless
  57.   you have to change the BaseIOAddress or Interrupt number and haven't
  58.   changed the CT-VOICE.DRV file itself.
  59.   Returns:  0 - no problem
  60.             1 - sound card failiure
  61.             2 - I/O failiure
  62.             3 - DMA interrupt failiure                                    }
  63.  
  64. procedure sb_output(sg,os:word);
  65. { Output the digitized sound.  You must load the sound first!
  66.   sg and os are the segment and offset of either SoundFile or whatever
  67.   array you use to store the sound.  If you use a .VOC file then call
  68.   with 26 added to the offset.                                            }
  69.  
  70. procedure sb_setstatusword(sg,os:word);
  71. { Sets the location of the status word.  This is the third thing you should
  72.   do, after loading the driver and initializing it.
  73.   The StatusWord will contain $0FFFF if input/output is in output, and
  74.   0 when it's done.  It will also hold the values of the markers in voice
  75.   files if any are encounterred, allowing you to coordinate output with
  76.   your programs.                                                          }
  77.  
  78. procedure sb_speaker(mode:word);
  79. { Set the speaker on/off.  Off is mode 0, and On is anything else.  This
  80.   is the fourth thing you should do in your initialization.               }
  81.  
  82. procedure sb_uninstall;
  83. { Uninstall the driver from memory.   Used by CloseDriver.                }
  84.  
  85. procedure sb_setIOaddress(add:word);
  86. { Override the IOaddress found inside the CT-VOICE.DRV file.  Add is the
  87.   new IO address.                                                         }
  88.  
  89. procedure sb_setinterruptnumber(intno:word);
  90. { Allows you to override the Interrupt number in the driver.  IntNo is your
  91.   new interrupt number (3, 5, 7 or 9).                                    }
  92.  
  93. procedure sb_stopoutput;
  94. { Stops the output in progress                                            }
  95.  
  96. function sb_pauseoutput: integer;
  97. { Pauses the output in progress.
  98.   Returns:  0 - success
  99.             1 - fail                                                      }
  100.  
  101. function sb_continueoutput: integer;
  102. { Continues a paused output.
  103.   Returns:  0 - success
  104.             1 - fail (nothing to continue)                                }
  105.  
  106. function sb_breakloop(mode:word): integer;
  107. { Breaks out of the currect output loop.
  108.   Modes:  0 - continue round, stop when done
  109.           1 - stop immediately
  110.   Returns:  0 - success
  111.             1 - not in loop                                               }
  112.  
  113. procedure sb_input(highlength,lowlength,seginputbuff,ofsinputbuff:word);
  114. { Input digitized sound.
  115.   HighLength: The high byte of the length of the input buffer.
  116.   LowLength:  The low byte of the length of the input buffer.
  117.   SegInputBuff: The Segment of the start of the input buffer.
  118.   OfsInputBuff: The Offset of the start of the input buffer.              }
  119.  
  120. procedure sb_setuserfunction(segaddress,ofsaddress:word);
  121. { Sets up a user function that the SB calls when it encounters a new data
  122.   block.  It must perform a FAR ret, preserve DS,DI,SI and flag register.
  123.   Clear Carry flag if you want the driver to process the block, or set it
  124.   if your routine will.  It must be clear if the block type is 0, that
  125.   is the terminate block.
  126.   SegAddress is the segment of your user function in memory.
  127.   OfsAddress is the ofset of your user function in memory.                }
  128.   
  129. implementation
  130.  
  131. uses DOS;
  132.  
  133. procedure Abort(s:string);
  134. begin
  135.   writeln('The Following Error Has Occurred: ',s);
  136.   writeln('Remedy and try again.  We apologize for any inconvenience.');
  137.   halt(1);
  138. end;
  139.  
  140. procedure loaddriver(fi:string);
  141. var f: file;
  142.     k: integer;
  143.     t: string[8];
  144. begin
  145.     assign(f,fi+'CT-VOICE.DRV');
  146.     {$I-} Reset(f,1); {$I+}
  147.     if IOResult <> 0 then
  148.         Abort('Cannot Open '+fi+'CT-VOICE.DRV');
  149.     blockread(f,Mem[sgSBDriver:ofSBDriver],filesize(f));
  150.     close(f);
  151.     t:='';
  152.     for k:=0 to 7 do
  153.         t:=t+chr(Mem[sgSBDriver:ofSBDriver+k+3]);
  154.     if t<>'CT-VOICE' then
  155.         abort('Invalid CT-VOICE Driver!');
  156. end;
  157.  
  158. procedure closedriver;
  159. begin
  160.     sb_uninstall;
  161.     if dalloc(sbdriver)=0 then
  162.         abort('Uninstall Error!');
  163. end;
  164.  
  165. procedure loadvoice(f:string;start,size:word);
  166. var fi: file;
  167.     k: word;
  168. begin
  169.     assign(fi,f);
  170.     {$I-} Reset(fi,1); {$I+}
  171.     if IOResult <> 0 then
  172.        abort('Cannot Open '+f+'!');
  173.     k:=0;
  174.     seek(fi,start);
  175.     if size=0 then size:=filesize(fi);
  176.     blockread(fi,Mem[seg(soundfile):ofs(soundfile)],size);
  177.     close(fi);
  178. end;
  179.  
  180. function sb_getversion: integer; assembler;
  181. asm
  182.    push  bp
  183.    mov   bx,0
  184.    call  SBDriver
  185.    pop   bp
  186. end;
  187.  
  188. procedure sb_setIOaddress(add:word); assembler;
  189. asm
  190.    push  bp
  191.    mov   bx,1
  192.    mov   ax,add
  193.    call  SBDriver
  194.    pop   bp
  195. end;
  196.  
  197. procedure sb_setinterruptnumber(intno:word); assembler;
  198. asm
  199.    push  bp
  200.    mov   bx,2
  201.    mov   ax,intno
  202.    call  SBDriver
  203.    pop   bp
  204. end;
  205.  
  206. procedure sb_stopoutput; assembler;
  207. asm
  208.    push  bp
  209.    mov   bx,8
  210.    call  SBDriver
  211.    pop   bp
  212. end;
  213.  
  214. function sb_init: integer; assembler;
  215. asm
  216.    push  bp
  217.    mov   bx, 3
  218.    call  SBDriver
  219.    pop   bp
  220. end;
  221.  
  222. function sb_pauseoutput: integer; assembler;
  223. asm
  224.    push  bp
  225.    mov   bx,10
  226.    call  SBDriver
  227.    pop   bp
  228. end;
  229.  
  230. function sb_continueoutput: integer; assembler;
  231. asm
  232.    push  bp
  233.    mov   bx,11
  234.    call  SBDriver
  235.    pop   bp
  236. end;
  237.  
  238. function sb_breakloop(mode:word): integer; assembler;
  239. asm
  240.    push  bp
  241.    mov   bx,12
  242.    mov   ax,mode
  243.    call  SBDriver
  244.    pop   bp
  245. end;
  246.  
  247. procedure sb_output(sg,os:word); assembler;
  248. asm
  249.     push bp
  250.     push di
  251.     mov  bx,6
  252.     mov  di,os             { offset of voice  }
  253.     mov  es,sg             { segment of voice }
  254.     call SBDriver
  255.     pop  di
  256.     pop  bp
  257. end;
  258.  
  259. procedure sb_input(highlength,lowlength,seginputbuff,ofsinputbuff:word); assembler;
  260. asm
  261.     push bp
  262.     push di
  263.     mov  bx,7
  264.     mov  dx,highlength
  265.     mov  cx,lowlength
  266.     mov  es,seginputbuff
  267.     mov  di,ofsinputbuff
  268.     call SBDriver
  269.     pop  di
  270.     pop  bp
  271. end;
  272.  
  273. procedure sb_setstatusword(sg,os:word); assembler;
  274. asm
  275.     push bp
  276.     push di
  277.     mov  bx,5
  278.     mov  di,os
  279.     mov  es,sg
  280.     call SBDriver
  281.     pop  di
  282.     pop  bp
  283. end;
  284.  
  285. procedure sb_speaker(mode:word); assembler;
  286. asm
  287.    push  bp
  288.    mov   bx,4
  289.    mov   ax,mode
  290.    call  SBDriver
  291.    pop   bp
  292. end;
  293.  
  294. procedure sb_uninstall; assembler;
  295. asm
  296.    push  bp
  297.    mov   bx,9
  298.    call  SBDriver
  299.    pop   bp
  300. end;
  301.  
  302. procedure sb_setuserfunction(segaddress,ofsaddress:word); assembler;
  303. asm
  304.    push  bp
  305.    mov   dx,segaddress
  306.    mov   ax,ofsaddress
  307.    mov   bx,13
  308.    call  SBDriver
  309.    pop   bp
  310. end;
  311.  
  312.  
  313. begin {set up SB}
  314.  
  315.   If DOSMemAvail < 2500 then                           { lower the heap   }
  316.       abort('Not Enough Memory');                      { with $M to fix   }
  317.   StatusWord:=MAlloc(SBDriver,2500);
  318.   if StatusWord<>0 then
  319.       abort('Memory Allocation Error');
  320.  
  321.   sgSBDriver:=MemW[seg(SBDriver):ofs(SBDriver)+2];
  322.   ofSBDriver:=MemW[seg(SBDriver):ofs(SBDriver)];
  323.  
  324.   Loaddriver('');                                      { change at will   }
  325.   if sb_init<>0 then                                   { or stick in your }
  326.       SBFound:=FALSE                                   { own program init }
  327.   else
  328.       SBFound:=TRUE;
  329.  
  330.   if SBFound then begin
  331.       sb_setstatusword(seg(statusword),ofs(statusword));
  332.       sb_speaker(1);                                   { turn SB on       }
  333.   end;
  334. end.
  335.